<template>
	<view>


		<view class="ptb">

			<view class="item plr" v-for="(item,index) in tablist" :key="index" v-if="tablist.length>0">

				<view class="gridSm g2">
					<view class="item" @click="msg(it,ind,item.data)" v-for="(it,ind) in item.data" :key="ind">
						<view class="flex pd10 rds5" style="background-color: #EDEEFF;">
							<view class="cover">
								<view class="fz16 bold">{{it.listname}}</view>
							</view>
							<image :src="it.cover" v-if="it.cover" mode="aspectFill" style="height: 60rpx;width:50rpx ;"></image>
						</view>
					</view>
				</view>

			</view>
		</view>
	</view>
</template>
<script>
	import _list from '@/util/list.js';
	import _qdcat from '@/util/qidian.js';
	export default {
		data() {
			return {
				tablist: [],
				type: ''
			}
		},
		onLoad(e) {
			if (e.type == 'male') {
				uni.setNavigationBarTitle({
					title: '男频'
				})
				this.type = 'male'
				this.getmale()
			} else {
				uni.setNavigationBarTitle({
					title: '女频'
				})
				this.type = 'female'
				this.getdata()
			}
		},
		methods: {
			getmale() {
				let _this = this
				_qdcat.getmale().then((res) => {

					_this.data(res.data, 2)

				});
			},
			getdata() {
				let _this = this
				_qdcat.getfemale().then((res) => {

					_this.data(res.data, 3)

				});
			},
			data(data, id) {
				if (this.type == 'male') {
					this.tablist = [{
						"catname": "男频",
						"sum": "",
						"data": [{
								"listname": "东方玄幻",
								"url": "https://weread.qq.com/web/bookListInCategory/1900001?maxIndex=20",
								"cid": "1900001",
								"pid": "1900001"
							},
							{
								"listname": "都市小说",
								"url": "https://weread.qq.com/web/bookListInCategory/1900002?maxIndex=20",
								"cid": "1900002",
								"pid": "1900002"
							},
							{
								"listname": "仙侠小说",
								"url": "https://weread.qq.com/web/bookListInCategory/1900003?maxIndex=20",
								"cid": "1900003",
								"pid": "1900003"
							},
							{
								"listname": "异界大陆",
								"url": "https://weread.qq.com/web/bookListInCategory/1900004?maxIndex=20",
								"cid": "1900004",
								"pid": "1900004"
							},
							{
								"listname": "异术超能",
								"url": "https://weread.qq.com/web/bookListInCategory/1900005?maxIndex=20",
								"cid": "1900005",
								"pid": "1900005"
							},
							{
								"listname": "玄幻奇幻",
								"url": "https://m.qidian.com/category/catid20076/subcatid20079-male",
								"cid": "1900006",
								"pid": "1900006"
							},
							{
								"listname": "同人二次元",
								"url": "https://m.qidian.com/category/catid20076/subcatid20096-male",
								"cid": "1900007",
								"pid": "1900007"
							},
							{
								"listname": "历史架空",
								"url": "https://m.qidian.com/category/catid20076/subcatid20096-male",
								"cid": "1900008",
								"pid": "1900008"
							},
							{
								"listname": "游戏竞技",
								"url": "https://m.qidian.com/category/catid20076/subcatid20096-male",
								"cid": "1900009",
								"pid": "1900009"
							},
							{
								"listname": "科幻未来",
								"url": "https://m.qidian.com/category/catid20076/subcatid20096-male",
								"cid": "1900010",
								"pid": "1900010"
							},
							{
								"listname": "时空穿梭",
								"url": "https://m.qidian.com/category/catid20076/subcatid20096-male",
								"cid": "1900011",
								"pid": "1900011"
							},
							{
								"listname": "悬疑灵异",
								"url": "https://m.qidian.com/category/catid20076/subcatid20096-male",
								"cid": "1900012",
								"pid": "1900012"
							},
							{
								"listname": "军事小说",
								"url": "https://m.qidian.com/category/catid20076/subcatid20096-male",
								"cid": "1900013",
								"pid": "1900013"
							}
						]
					}]
				} else {
					this.tablist = [{
						"catname": "女频",
						"sum": "",
						"data": [{
								"listname": "穿越架空",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000001",
								"pid": "2000001"
							},
							{
								"listname": "豪门世家",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000002",
								"pid": "2000002"
							},
							{
								"listname": "现代言情",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000003",
								"pid": "2000003"
							},
							{
								"listname": "玄幻言情",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000004",
								"pid": "2000004"
							},
							{
								"listname": "古代言情",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000005",
								"pid": "2000005"
							},
							{
								"listname": "快穿小说",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000006",
								"pid": "2000006"
							},
							{
								"listname": "宫闱宅斗",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000007",
								"pid": "2000007"
							},
							{
								"listname": "仙侠奇缘",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000008",
								"pid": "2000008"
							},
							{
								"listname": "重生异能",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000009",
								"pid": "2000009"
							},
							{
								"listname": "经商种田",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000010",
								"pid": "2000010"
							},
							{
								"listname": "青春言情",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000011",
								"pid": "2000011"
							},
							{
								"listname": "科幻神秘",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000012",
								"pid": "2000012"
							},
							{
								"listname": "游戏竞技",
								"url": "https://weread.qq.com/web/bookListInCategory/2000001?maxIndex=20",
								"cid": "2000013",
								"pid": "2000013"
							},
						]
					}]
				}


				this.tablist[0].data.forEach((item, index) => {
					

					 this.cat(item.cid,index)
					
				})
				
console.log('xxxxxxxxxxx',)
			},
			  cat(id,index) {
				let cover = _qdcat.categories(id, 0, 0).then( async (res) => {
					this.tablist[0].data[index].cover=res[0].bookInfo.cover
					this.$forceUpdate()
				});
				
			},
			msg(msg, ind, data) {
				let url = '/pages/index/listitem?type=' + this.type + '&major=' + msg.listname + '&cid=' + msg.cid +
					'&pid=' + msg.pid + '&index=' + ind

				uni.setStorageSync('list_cat', data);
				uni.navigateTo({
					url: url
				});
			}

		}
	}
</script>
<style lang="scss">
	@import "common/css/base-view.scss";

	page {
		background: #fff;
		color: #33363A;
	}

	.swiper-box {
		image {
			width: 100%;
			height: 300rpx;
		}
	}

	.bg {
		background-color: #FFFFFF;
		padding: 60rpx 20rpx 0rpx 20rpx;
		margin-bottom: 40px;
		border-radius: 10rpx;
	}
</style>